package mesweb.mesweb.controller.produce;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farvision.common.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import mesweb.mesweb.dto.ProducePlan.DayReportDetailConditionDto;
import mesweb.mesweb.entity.produce.ProduceWEDF;
import mesweb.mesweb.service.produce.IProduceWEDFService;
import mesweb.mesweb.vo.produce.ProduceWEDFVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 物料齐套
 * @Author: jeecg-boot
 * @Date:   2021-09-02
 * @Version: V1.0
 */

@Api(tags="物料齐套")
@RestController
@RequestMapping("/mes/produceWEDF")
public class ProduceWEDFController {
	@Autowired
	private IProduceWEDFService produceWEDFService;


    @GetMapping("/GetAll")
    @ApiOperation("获取全部数据列表")
    public CommonResult<?> GetAll(@ApiParam("名称") @RequestParam( value = "name",required = false) String name) {
        List<ProduceWEDF> data = new ArrayList<>();
        if (StringUtils.isBlank(name) || name.equals("全部")) {
            data = produceWEDFService.list();
        } else {
            QueryWrapper<ProduceWEDF> queryWrapper = new QueryWrapper<>();
            data = produceWEDFService.list(queryWrapper);
        }
        return CommonResult.success(data);
    }
	/**
	 * 分页列表查询
	 *
	 * @param produceWEDF
	 * @param page
	 * @param size
	 * @param req
	 * @return
	 */
	@ApiOperation(value="物料齐套-分页列表查询", notes="物料齐套-分页列表查询")
	@GetMapping(value = "/list")
	public CommonResult<?> queryPageList(ProduceWEDF produceWEDF,
								   @RequestParam(name="page", defaultValue="1") Integer page,
								   @RequestParam(name="size", defaultValue="2") Integer size,
								   HttpServletRequest req) {
		QueryWrapper<ProduceWEDFVo> queryWrapper = new QueryWrapper<>();
		Page<ProduceWEDFVo> pageProduceWEDF = new Page<ProduceWEDFVo>(page, size);
		IPage<ProduceWEDFVo> pageList = produceWEDFService.checkCurrentWEDF(pageProduceWEDF, queryWrapper);
		return CommonResult.success(pageList);
	}
	/**
	 * 编辑
	 *
	 * @param produceWEDF
	 * @return
	 */
	@ApiOperation(value="物料齐套-编辑", notes="物料齐套-编辑")
	@PostMapping(value = "/save")
	public CommonResult<?> edit(@RequestBody ProduceWEDF produceWEDF) {
       boolean result = false;
        if(produceWEDF.getId() == 0L) {
             result = produceWEDFService.save(produceWEDF);
        }
        else
        {
            result = produceWEDFService.updateById(produceWEDF);
        }
        return CommonResult.success(result);
	}

	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="物料齐套-通过id删除", notes="物料齐套-通过id删除")
	@DeleteMapping(value = "/delete")
	public CommonResult<?> delete(@RequestParam(name="id",required=true) String id) {
		produceWEDFService.removeById(id);
		return CommonResult.success("删除成功!");
	}

	/**
	 * 批量删除
	 *
	 * @param ids
	 * @return
	 */
	@ApiOperation(value="物料齐套-批量删除", notes="物料齐套-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public CommonResult<?> deleteBatch(@ApiParam("ProduceWEDFIDs") @RequestBody List<Long> ids) {
		this.produceWEDFService.removeByIds(ids);
		return CommonResult.success("批量删除成功！");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="物料齐套-通过id查询", notes="物料齐套-通过id查询")
	@GetMapping(value = "/queryById")
	public CommonResult<?> queryById(@RequestParam(name="id",required=true) String id) {
		ProduceWEDF produceWEDF = produceWEDFService.getById(id);
		return CommonResult.success(produceWEDF);
	}



	@GetMapping("/GetAllProductMaterial")
	@ApiOperation("获取全部产品bom")
	public CommonResult<?> GetAllProductMaterial(@ApiParam("名称") DayReportDetailConditionDto dayReportDetailConditionDto) {
		List<ProduceWEDFVo> resutl = produceWEDFService.getProductMaterial(dayReportDetailConditionDto);
		return CommonResult.success(resutl);
	}

	/**
	 * 分页列表查询
	 *
	 * @param dayReportDetailConditionDto
	 * @param page
	 * @param size
	 * @param req
	 * @return
	 */
	@ApiOperation(value="物料齐套-分页列表查询", notes="物料齐套-分页获取产品bom")
	@GetMapping(value = "/getProductMaterial")
	public CommonResult<?> getProductMaterial(DayReportDetailConditionDto dayReportDetailConditionDto,
											  @RequestParam(name="page", defaultValue="1") Integer page,
											  @RequestParam(name="size", defaultValue="2") Integer size,
											  HttpServletRequest req) {
		Page<ProduceWEDFVo> pageProduceWEDF = new Page<ProduceWEDFVo>(page, size);
		IPage<ProduceWEDFVo> pageList = produceWEDFService.getProductMaterial(pageProduceWEDF, dayReportDetailConditionDto);
		return CommonResult.success(pageList);
	}

	@GetMapping("/getAllOrderProductMaterial")
	@ApiOperation("获取全部产品bom")
	public CommonResult<?> GetAllOrderProductMaterial(@ApiParam("名称") DayReportDetailConditionDto dayReportDetailConditionDto) {
		List<ProduceWEDFVo> resutl = produceWEDFService.getOrderProductMaterial(dayReportDetailConditionDto);
		return CommonResult.success(resutl);
	}

	/**
	 * 分页列表查询
	 *
	 * @param dayReportDetailConditionDto
	 * @param page
	 * @param size
	 * @param req
	 * @return
	 */
	@ApiOperation(value="物料齐套-分页列表查询", notes="物料齐套-分页获取产品bom")
	@GetMapping(value = "/getOrderProductMaterial")
	public CommonResult<?> getOrderProductMaterial( DayReportDetailConditionDto dayReportDetailConditionDto,
											  @RequestParam(name="page", defaultValue="1") Integer page,
											  @RequestParam(name="size", defaultValue="2") Integer size,
											  HttpServletRequest req) {
		Page<ProduceWEDFVo> pageProduceWEDF = new Page<ProduceWEDFVo>(page, size);
		IPage<ProduceWEDFVo> pageList = produceWEDFService.getOrderProductMaterial(pageProduceWEDF, dayReportDetailConditionDto);
		return CommonResult.success(pageList);
	}
}
